﻿/*****************************************介绍*****************************************
 * 作者：User
 * 创建时间：2025-09-08 15:19:40
 * 功能：相册页面的开关状态控制
**************************************************************************************/

using UnityEngine;
using UnityEngine.UI;

namespace Game.UI.HallPanel
{
    public class SwitchStatusGallery : MonoBehaviour
    {
        private Toggle m_Switch;
        private Text m_Label;
        [SerializeField] private Color m_OnColor;
        [SerializeField] private Color m_OffColor;
        private Vector2 m_DefPos;

        private void Awake()
        {
            m_Switch = GetComponent<Toggle>();
            m_Label = transform.Find("Label").GetComponent<Text>();
            m_DefPos = m_Label.rectTransform.anchoredPosition;

            m_Switch.onValueChanged.AddListener(OnSwitchValueChanged);
            OnSwitchValueChanged(m_Switch.isOn);
        }

        private void OnSwitchValueChanged(bool isOn)
        {
            m_Label.color = isOn ? m_OnColor : m_OffColor;
            m_Label.rectTransform.localScale = Vector3.one * (isOn ? 1.3f : 1f);
            m_Label.rectTransform.anchoredPosition = isOn ? new Vector2(0, 25f) : m_DefPos;
        }
    }
}